package com.myself.ssoserver.repository

import com.myself.common.repository.BaseRepository
import com.myself.ssoserver.entity.*
import com.myself.ssoserver.entity.TriLotteries.triLotteries
import com.myself.ssoserver.entity.TriVersions.triVersions
import org.ktorm.database.Database
import org.ktorm.dsl.desc
import org.ktorm.dsl.eq
import org.ktorm.entity.*
import org.springframework.stereotype.Repository

@Repository
open class TriLotteryRepository(private val dataBase: Database) :
    BaseRepository<TriLottery, TriLotteries>(dataBase.triLotteries) {
    open fun findByUserId(id: Int): List<TriLottery> {
        return sequence.filter { it.userId eq id }.sortedBy { it.createTime.desc() }.toList()
    }
}


@Repository
open class TriVersionRepository(private val dataBase: Database) :
    BaseRepository<TriVersion, TriVersions>(dataBase.triVersions) {
    open fun findCurrent(): TriVersion {
        return sequence.filter { it.status eq "1" }.sortedBy { it.id.desc() }.first()
    }

    open fun findReady(): TriVersion {
        return sequence.filter { it.status eq "2" }.sortedBy { it.id.desc() }.first()
    }
}